package top.ly61.core.controller.admin;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.ly61.common.exception.Assert;
import top.ly61.common.result.ResponseEnum;
import top.ly61.common.result.Result;
import top.ly61.core.pojo.entity.Student;
import top.ly61.core.service.StudentService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author suk_mit
 * @Date 2022/1/27 12:38
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/student")
public class AdminStudentController {

    @Autowired
    StudentService studentService;

    /**
     * 获取所有学生的信息
     * @return
     */
    @GetMapping("/all")
    public Result getAllStudents() {
        Result result = new Result();
        List<Student> list = studentService.list();
        Assert.isNull(list, ResponseEnum.WEIXIN_FETCH_USERINFO_ERROR);
        result.setCode(200);
        result.setMessage("请求成功！");
        Map<String,Object> map = new HashMap<>();
        map.put("Date",list);
        result.setData(map);
        return result;
    }

    /**
     * 通过学号获取学生信息
     * @param id
     * @return
     */
    @GetMapping("/getStudent/{id}")
    public Result getStudentById(@PathVariable("id") String id) {
        Student student = studentService.getById(id);
        Assert.isNull(student,ResponseEnum.WEIXIN_FETCH_USERINFO_ERROR);
        Result result = new Result();
        result.setCode(200);
        Map<String,Object> map = new HashMap<>();
        map.put("Date",student);
        return result;
    }

}
